#include <stdio.h>
#include <stdlib.h>

// 定义节点结构体
typedef struct node {
    int payload; // 节点的值
    struct node* next; // 指向下一个节点的指针
} node;

// 添加节点函数
node* add(node* tail) {
    if(tail == NULL){
        tail = (node*)malloc(sizeof (node));
        tail->next = tail;
        return tail;
    } else{
        node* newNode = (node*)malloc(sizeof(node));
        newNode->next = tail->next;
        tail->next = newNode;
        return newNode;
    }
}

//一开始写的
//void joseph(node* tail, int step){
//    if(tail == NULL) return;
//    node* move = tail;
//    node* pre = tail;
//    while (move!=move->next){
//        pre = move;
//        move = move->next;
//        for (int i = 1; i < step; ++i) {
//            pre = pre->next;
//            move = move->next;
//        }
//        if(move == NULL) break;
//        printf("%d ",move->payload);
//        pre->next = move->next;
//        free(move);
//        move = pre;
//    }
//    printf("%d",move->payload);
//}

//改进后
void joseph(node* tail, int step){
    if (tail == NULL) return;
    node* current = tail->next;
    node* prev = tail;
    while (current->next!= current) {
        for (int i = 1; i < step; ++i) {
            prev = current;
            current = current->next;
        }
        prev->next = current->next;
        printf("%d ",current->payload);
        current = prev->next;
    }
    printf("%d",current->payload);
    free(current);
}

int main() {
    // 初始化尾指针为 NULL
    node* tail = NULL;
    int n,t;
    // 从标准输入读取节点数量 n 和步长 t
    scanf("%d%d",&n,&t);
    // 循环添加节点构建链表
    for (int i = 1; i <= n; i++) {
        tail = add(tail);
        tail->payload = i;
    }
    // 调用消除节点函数
    joseph(tail, t);
    return 0;
}